﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ScheduleManagement.UI
{
    public partial class ClosePoint : Form
    {
        public ClosePoint()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 选择按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ClosePoint_Load(object sender, EventArgs e)
        {
            //当用户选中某个退出事件
            string Exit = ((RadioButton)sender).Text;//选择的按钮
        }

        /// <summary>
        /// 确定退出按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (rdoExit.Checked)
            {
                Application.Exit();//如果选择直接退出，关闭整个程序
            }
            else
            {
                #region 源代码
                //选择最小化到系统托盘处，最小化窗口
                //this.Close();
                //frm_Main frm_main = new frm_Main();
                //this.WindowState = FormWindowState.Minimized;
                //this.notifyIcon1.Visible = true;
                #endregion
                //this.notifyIcon.Visible = false;
                this.Close();
                this.Dispose();
                Application.Exit();
            }
        }

        #region 私有方法
                /// <summary>
                /// 隐藏主窗体
                /// </summary>
                private void Hidefrm_Main()
                {
                    this.Hide();
                }

                /// <summary>
                /// 显示主窗体
                /// </summary>
                private void Showfrm_Main()
                {
                    this.Show();
                    this.WindowState = FormWindowState.Normal;
                    this.Activate();
                }
        #endregion

        /// <summary>
        /// 取消按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnNO_Click(object sender, EventArgs e)
        {
            frm_Main frm_main = new frm_Main();
            frm_main.Show();
            this.Close();//关闭此退出窗口
        }

        #region 双击托盘上图标时，显示窗体
        /// <summary>
        /// 将窗体从任务栏点击出来的
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (this.WindowState == FormWindowState.Normal)
            {
                this.WindowState = FormWindowState.Minimized;

                Hidefrm_Main();
            }
            else if (this.WindowState == FormWindowState.Minimized)
            {
                Showfrm_Main();
            }
        }
        #endregion

        #region 点最小化按钮时，最小化到托盘
        //private void frm_Main_SizeChanged(object sender, EventArgs e)
        //{
        //    if (this.WindowState == FormWindowState.Minimized)
        //    {
        //        Hidefrm_Main();
        //    }
        //}
        #endregion

        #region 窗体关闭时最小化到托盘
        //private void frm_Main_FormClosing(object sender, FormClosingEventArgs e)
        //{
        //    e.Cancel = true;

        //    Hidefrm_Main();
        //}
        #endregion 

        //private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        //{
        //    this.WindowState = FormWindowState.Normal;
        //    this.Visible = true;
        //}
    }
}